package com.briup.exception;


import com.briup.util.Result;
import com.briup.util.ResultCode;
import com.briup.util.ResultUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@Slf4j
@RestControllerAdvice
public class GlobalExceptionHandler {
    @ExceptionHandler(Exception.class)
    public Result handleException(Exception e){

        log.error("进行全局异常处理");
        e.printStackTrace();
        if(e instanceof CustomException){
            return ResultUtil.error(((CustomException) e).getCode());
        }
        return ResultUtil.error(ResultCode.SERVER_INTER_ERROR);
    }
}
